import java.util.Scanner;

public class Test {
    public static void main(String[] ages) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i <= n; i++) {//遍历1到n
            int tmp = i;
            int count = 0;//记录该数字是几位数
            //算出count的值
            while (tmp != 0) {
                tmp /= 10;
                count++;
            }
            tmp = i;
            int sum = 0;
            while (tmp != 0) {//计算个位数的count次方和与该数是否相同
                sum += Math.pow(tmp % 10, count);
                tmp /= 10;
            }
            if (sum == i) {
                System.out.println(i + " ");
            }
        }
    }
}
